#!/bin/bash

BUILD_ID=dontKillMe
cd /opt/jen-space

kubectl create ns $3
kubectl delete -f $1-dep.yaml
kubectl delete -f $1-svc.yaml
#这里速度太快会导致docker rmi删不掉，所以停留3秒钟
sleep 3
docker rmi 192.168.63.20:10080/library/$1:latest -f
ssh node1 -p 10022 "docker rmi 192.168.63.20:10080/library/$1:latest"
ssh node2 -p 10022 "docker rmi 192.168.63.20:10080/library/$1:latest"
ssh node3 -p 10022 "docker rmi 192.168.63.20:10080/library/$1:latest"

docker login --username=admin --password=Harbor12345  192.168.63.20:10080

#/opt/opt/jen-space/drun.sh $1 $2 $3 $4 $5
sed -e 's/jarname/'$1'.jar/g' -e 's/pt/'$2'/g'  Dockerfile.base > Dockerfile
sed -e 's/jarname/'$1'/g' -e 's/ns/'$3'/g' -e 's/num/'$4'/g'  dep.yaml.base > $1-dep.yaml
sed -e 's/jarname/'$1'/g' -e 's/pt/'$2'/g'  -e 's/ns/'$3'/g' -e 's/np/'$5'/g'  svc.yaml.base > $1-svc.yaml

docker build -t 192.168.63.20:10080/library/$1:latest .
docker push 192.168.63.20:10080/library/$1:latest
docker rmi 192.168.63.20:10080/library/$1:latest

docker pull 192.168.63.20:10080/library/$1:latest
kubectl apply -f $1-dep.yaml
kubectl apply -f $1-svc.yaml


